//
//  detectorViewController.swift
//  01-HB二维码-基本结构搭建
//
//  Created by xmg on 16/5/21.
//  Copyright © 2016年 haibo. All rights reserved.
//

import UIKit
import CoreImage
class detectorViewController: UIViewController {

  @IBOutlet weak var detectorImageView: UIImageView!
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        //创建一个二维码探测器
        let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy : CIDetectorAccuracyHigh])
        //探测二维码照片的特征
        guard let image = detectorImageView.image else {
            return
        }
        let imageIC = CIImage(image: image)
        let features = detector.featuresInImage(imageIC!)
        //处理识别到的特征值
        for feature in features {
            if feature.isKindOfClass(CIQRCodeFeature) {
                let qrCodeFeature = feature as! CIQRCodeFeature
                print(qrCodeFeature.messageString)
            }
        }
    }

}
